package com.AICoupon.config;

import com.AICoupon.repository.RedisChatMemoryStore;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.openai.OpenAiChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonConfig {
    @Autowired
    private OpenAiChatModel openAiChatModel;
    @Autowired
    private RedisChatMemoryStore RedisChatMemoryStore;

//    @Bean
//    public ChatMemory chatMemory() {
//        MessageWindowChatMemory memory = MessageWindowChatMemory.builder()
//                .maxMessages(20)
//                .build();
//        return memory;
//    }
    //构建chatMemoryProvider对象
    @Bean
    public ChatMemoryProvider chatMemoryProvider(){
        ChatMemoryProvider chatMemoryProvider = new ChatMemoryProvider() {
            @Override
            public ChatMemory get(Object memoryId) {
                    return MessageWindowChatMemory.builder()
                            .id(memoryId)
                        .maxMessages(20)
                            .chatMemoryStore(RedisChatMemoryStore)
                        .build();

            }
        };
           return chatMemoryProvider;
    }


}
